package myky.com.doctorapp.presenter

import io.reactivex.disposables.Disposable
import myky.com.doctorapp.api.ResponseTransformer
import myky.com.doctorapp.api.schedulers.SchedulerHelper
import myky.com.doctorapp.base.BasePresenterIm
import myky.com.doctorapp.base.SimpleSubscribe
import myky.com.doctorapp.contract.FindDoctorSeachContract
import myky.com.doctorapp.model.FindDoctorSeachModel

class FindDoctorSeachPresenter : BasePresenterIm<FindDoctorSeachContract.View>(), FindDoctorSeachContract.Presenter {
    private var findDoctorSeachModel: FindDoctorSeachModel = FindDoctorSeachModel()

    override fun findReleseContent(content: String, type: Int) {
        findDoctorSeachModel.findReleseContent(content, type)
                .compose<List<String>>(ResponseTransformer.handleResult<List<String>>())
                .compose<List<String>>(SchedulerHelper.applySchedulers<List<String>>())
                .subscribe(object : SimpleSubscribe<List<String>>() {
                    override fun onSubscribe(d: Disposable) {
                        addSubscription(d)
                    }

                    override fun onFailed(msg: String?) {
                        mView.showDataError(msg)
                    }

                    override fun onSuccess(t: List<String>?) {
                        t?.let {
                            mView.showReleaseContent(it)
                        }
                    }
                })
    }
}
